            let currentIndex = 0;
            const slides = document.querySelectorAll('.slide');
            const totalSlides = slides.length;
            const intervalTime = 3000; // 设置自动播放的时间间隔，单位为毫秒

            document.querySelector('.prev').addEventListener('click', () => {
                currentIndex = (currentIndex > 0) ? currentIndex - 1 : totalSlides - 1;
                updateCarousel();
            });

            document.querySelector('.next').addEventListener('click', () => {
                currentIndex = (currentIndex < totalSlides - 1) ? currentIndex + 1 : 0;
                updateCarousel();
            });

            function updateCarousel() {
                const slideWidth = slides[0].clientWidth;
                const newTransformValue = -currentIndex * slideWidth;
                document.querySelector('.slides').style.transform = `translateX(${newTransformValue}px)`;
            }

            // 自动播放功能
            let autoPlay = setInterval(() => {
                currentIndex = (currentIndex < totalSlides - 1) ? currentIndex + 1 : 0;
                updateCarousel();
            }, intervalTime);

            // 鼠标悬停时停止自动播放，移开时继续自动播放
            document.querySelector('.carousel').addEventListener('mouseover', () => {
                clearInterval(autoPlay);
            });

            document.querySelector('.carousel').addEventListener('mouseout', () => {
                autoPlay = setInterval(() => {
                    currentIndex = (currentIndex < totalSlides - 1) ? currentIndex + 1 : 0;
                    updateCarousel();
                }, intervalTime);
            });